import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/13 10:51
 * @description
 */
public class Solution {
    int[] origin;
    int[] change;
    Random random;
    public Solution(int[] nums) {
        origin = Arrays.copyOf(nums, nums.length);
        change = nums;
        random = new Random();
    }

    public int[] reset() {
        return origin;
    }

    public int[] shuffle() {
        for (int i = 0; i < change.length; i++) {
            int index = random.nextInt(change.length - i);
            if (index != change.length - i - 1) {
                // 不是数组最后一位，需要交换
                int temp = change[change.length - i - 1];
                change[change.length - i - 1] = change[index];
                change[index] = temp;
            }
        }
        return change;
    }


    public static void main(String[] args) {
        int[] n = {1, 2 ,3};
        Solution solution = new Solution(n);
        solution.shuffle();    // 打乱数组 [1,2,3] 并返回结果。任何 [1,2,3]的排列返回的概率应该相同。例如，返回 [3, 1, 2]
        solution.reset();      // 重设数组到它的初始状态 [1, 2, 3] 。返回 [1, 2, 3]
        solution.shuffle();    // 随机返回数组 [1, 2, 3] 打乱后的结果。例如，返回 [1, 3, 2]

    }
}
